﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vms.Web.Models;
using System.Data;
using System.Data.Entity;
using Vms.Web.Lib;
using Vms.Web.Services;

namespace Vms.Web.Controllers
{
    public class DashboardController : Controller
    {
        private VmsWebContext context = new VmsWebContext();
        //
        // GET: /SCREENs/

        public ViewResult Index()
        {
            List<SCREEN> screens = context.SCREENS.ToList();
            //foreach (var item in screens)
            //{
            //    item.PROGRAMS = context.PROGRAMS.Where(p => p.);

            //}

        //   IQueryable scrs = context.SCREENS.Include(screen => screen.PROGRAMS).Include(scr => scr.ScreenStatus).Include(s =>s.PROGRAMS.Single().CONTENTS);
            return View(screens);
        }

        public ActionResult TurnOnScreen(int screenId, int isOn)
        {
            if (isOn == 1)
            {
                BoardServices.TurnOnScreen(screenId);
            }
            else
            {
                BoardServices.TurnOnScreen(screenId, false);
            }
            return RedirectToAction("Index", "Dashboard");
        }

        public ActionResult SendProgramToScreen(int screenId)
        {
            BoardServices.SendProgramToScreen(screenId);
            return RedirectToAction("Index", "Dashboard");
        }

    }
}
